package top.hitotright.hdfs;

import java.io.IOException;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class Tool {
	public static void main(String[] args)throws IOException {
		if(args.length < 1) {
			System.out.println("java jar top.hitotright.hdfs.FileSystem [hdfs host] [port(9000)]");
			System.exit(1);
		}
		int port = 9000;
		if(args.length > 1) {
			port = Integer.parseInt(args[1]);
		}
		String uri = "hdfs://"+args[0]+":"+port+"/";
		Configuration conf = new Configuration();
		FileSystem fs = FileSystem.get(URI.create(uri),conf);
		Path path = new Path(uri);
		FileStatus status[] = fs.listStatus(path);
		for (int i = 0; i < status.length; i++) {
			System.out.println(status[i].getPath().toString());
//			status[i].isDirectory();
		}
	}
}
